feat(rich-text-field): add RichTextField component#409
Merged
Conversation
fabiankaegy
reviewed
May 12, 2026
Comment on lines
+36
to
+61
| useEffect(() => { | ||
| if (!isSelected) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const doc = ref.current?.ownerDocument; | ||
| if (!doc) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const handleMouseDown = (event: MouseEvent) => { | ||
| const target = event.target as HTMLElement | null; | ||
| if (ref.current?.contains(target)) { | ||
| return; | ||
| } | ||
| if (target?.closest?.('.block-editor-rich-text__inline-format-toolbar')) { | ||
| return; | ||
| } | ||
| if (target?.closest?.('.components-popover')) { | ||
| return; | ||
| } | ||
| setIsSelected(false); | ||
| }; | ||
|
|
||
| doc.addEventListener('mousedown', handleMouseDown); | ||
| return () => doc.removeEventListener('mousedown', handleMouseDown); |
Member
There was a problem hiding this comment.
Can this get replaced by the useRefEffect hook?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of the Change
Adds a new
RichTextFieldcomponent: a drop-in wrapper aroundRichTextfor use outside a block'seditcontext (e.g. insideInspectorControlsor aModal).RichTextonly works correctly inside a block'seditbecause the surrounding block-editor infrastructure provides aSlotFillProvider, a block-selection store, and aBlockControlsslot for the format toolbar. When rendered outside that context, the format toolbar disappears, selection state is missing, and formatting fills get captured by the parent block's toolbar.RichTextFieldsolves this by providing:SlotFillProviderso the format toolbar resolves inside the field instead of leaking into the surrounding block's toolbar.inlineToolbarso the format toolbar renders as a popover near the caret.isSelectedstate with click-outside deselect that ignores the inline toolbar and any popovers it spawns (e.g. the link URL input).The component accepts all
RichTextprops exceptisSelected(managed internally) and forwards everything else through.Files added/changed:
components/rich-text-field/index.tsx— component implementation (TypeScript).components/rich-text-field/readme.md— usage, props, and modalz-indexnote.components/index.ts— exportRichTextField.README.md— list the new component.Closes #
How to test the Change
npm install && npm run buildin this repo.InspectorControlspanel:RichTextFieldrendered inside aModal. If the inline toolbar appears behind the modal, apply the CSS override documented incomponents/rich-text-field/readme.md.tagName,placeholder,allowedFormats, andclassNameprops all forward correctly.Changelog Entry
Credits
Props @s3rgiosan
Checklist: